package cn.jcby.app.lebu.controller;


import cn.jcby.app.lebu.controller.req.*;
import cn.jcby.app.lebu.controller.res.PlaningInfoRes;
import cn.jcby.app.lebu.controller.res.UserMotionPlanInfoRes;
import cn.jcby.app.lebu.controller.res.UserMotionPlanListRes;
import cn.jcby.app.lebu.service.UserMotionPlanService;
import cn.jcby.app.lebu.utils.PageUtils;
import cn.jcby.app.lebu.utils.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;



/**
 * 计划管理
 *
 * @author lht
 * @email 
 * @date 2023-12-07 15:13:35
 */
@RestController
@RequestMapping("/motion/plan")
@Api(tags="运动计划管理")
public class UserMotionPlanController {
    @Autowired
    private UserMotionPlanService userMotionPlanService;


    //计划列表：头像 运动类型 标题 开始位置/场馆 能量值


    //发起人新发布列表
    @ApiOperation("发布人新发布列表")
    @PostMapping("/publisherList")
    @ApiResponses({
          @ApiResponse(code = 200,message = "ok",response = UserMotionPlanListRes.class)
    })
    public Result publisherList(@RequestBody @Validated PublisherListReq req){
        PageUtils page = userMotionPlanService.publisherNewPage(req);
        return Result.ok().put("data", page);
    }
    /**
     *
     * @param params
     * @return
     */
    @ApiOperation("我的运动记录")
    @PostMapping("/myMotionList")
    @ApiResponses({
            @ApiResponse(code = 200,message = "ok",response = UserMotionPlanListRes.class)
    })
    public Result myMotionList(@RequestBody @Validated UserMotionPlanListReq params){
        PageUtils page = userMotionPlanService.myMotionPage(params);
        return Result.ok().put("data", page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation("计划详情")
    @ApiResponses({
         @ApiResponse(code = 200,message = "ok",response = UserMotionPlanInfoRes.class)
    })
    public Result info(@PathVariable("id") String id){
        UserMotionPlanInfoRes data = userMotionPlanService.getInfoById(id);
        return Result.ok().put("data", data);
    }
    @GetMapping("/planingInfo/{id}")
    @ApiOperation("进行中的详情：如开始跑步后")
    @ApiResponses({
         @ApiResponse(code = 200,message = "ok",response = PlaningInfoRes.class)
    })
    public Result planingInfo(@PathVariable("id") String id){
        PlaningInfoRes data = userMotionPlanService.planingInfo(id);
        return Result.ok().put("data", data);
    }

    /**
     * 保存
     */
    @PostMapping("/addPlan")
    @ApiOperation("添加计划")
    public Result save(@Validated @RequestBody AddUserMotionPlanReq req){
        userMotionPlanService.add(req);
        return Result.ok();
    }

    //参与人参与计划
    @PostMapping("/joinPlan")
    @ApiOperation("参与人参与计划")
    public Result joinPlan(@RequestParam("id")@ApiParam(value = "计划id") String id){
        userMotionPlanService.joinPlan(id);
        return Result.ok();
    }
    //参与人取消计划
    @PostMapping("/cancelJoinPlan")
    @ApiOperation("参与人取消参与计划")
    public Result cancelJoinPlan(@RequestParam("id")@ApiParam(value = "计划id") String id){
        userMotionPlanService.cancelJoinPlan(id);
        return Result.ok();
    }

    //发起人取消计划
    @PostMapping("/proCancelJoinPlan")
    @ApiOperation("发起人取消计划")
    public Result proCancelJoinPlan(@RequestParam("id")@ApiParam(value = "计划id") String id){
        userMotionPlanService.proCancelJoinPlan(id);
        return Result.ok();
    }

    /**
     * 发起人删除计划、发起人/参与人删除已完成的计划
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除计划")
    public Result delete(@RequestParam("id") String id){
        userMotionPlanService.deleteById(id);
        return Result.ok();
    }
    //参与人强制结束计划
    @PostMapping("/forceEndPlan")
    @ApiOperation("参与人强制结束计划")
    public Result forceEndPlan(@RequestParam("id")@ApiParam(value = "计划id") String id){
        userMotionPlanService.forceEndPlan(id);
        return Result.ok();
    }
    //发起人开始计划（参与人反向客户端获取定位），返回相关属性：运动类型、耗时、距离
    @PostMapping("/startPlan")
    @ApiOperation("发起人开始计划（参与人反向客户端获取定位）")
    public Result startPlan(@RequestBody @Validated UserStartPlanReq req){
        userMotionPlanService.startPlan(req) ;
        return Result.ok();
    }

    //完成计划（未完成退回金额，已完成消耗金钱）
    @PostMapping("/finishPlan")
    @ApiOperation("完成计划（未完成退回金额，已完成消耗金钱）")
    public Result finishPlan(@RequestBody @Validated FinishPlanReq req){
        userMotionPlanService.finishPlan(req);
        return Result.ok();
    }

}
